local sk__zhengyi = fk.CreateSkill {

  name = "sk__zhengyi",

  tags = {},

}



sk__zhengyi:addEffect("viewas", {
  name = "sk__zhengyi",
  pattern = ".|.|.|.|.|basic",
  prompt = function(self, player)
    if player:getHandcardNum() < player.hp then
      return "#sk__zhengyi-draw"
    else
      return "#sk__zhengyi-discard"
    end
  end,
  interaction = function(self, player)
    local all_names = Fk:getAllCardNames("b")
    local names = player.getViewAsCardNames(player, sk__zhengyi.name, all_names)
    return UI.CardNameBox { choices = names, all_choices = all_names, }
  end,
  card_filter = function(self, player, to_select, selected)
    if player:getHandcardNum() < player.hp then
      return false
    else
      return #selected == 0 and Fk:currentRoom():getCardArea(to_select) == Card.PlayerHand and
      not player:prohibitDiscard(to_select)
    end
  end,
  before_use = function(self, player, use)
    local id = use.card:getMark(sk__zhengyi.name)
    if id == 0 then
      player:drawCards(1, sk__zhengyi.name)
    elseif id ~= 0 and table.contains(player:getCardIds("h"), id) then
      player.room:throwCard(id, sk__zhengyi.name, player, player)
    end
  end,
  view_as = function(self, player, cards)
    if not self.interaction.data then return end
    local card = Fk:cloneCard(self.interaction.data)
    if player:getHandcardNum() > player.hp then
      if #cards ~= 1 then return end
      card:setMark(sk__zhengyi.name, cards[1])
    end
    card.skillName = sk__zhengyi.name
    return card
  end,
  enabled_at_play = function(self, player)
    return math.abs(player:getHandcardNum() - math.max(player.hp, 0)) == 1
  end,
  enabled_at_response = function(self, player, response)
    return not response and math.abs(player:getHandcardNum() - math.max(player.hp, 0)) == 1
  end,
})

return sk__zhengyi
